import path from 'path'
import ts from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import babel from 'rollup-plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import json from 'rollup-plugin-json'
import css from 'rollup-plugin-css-porter'
import postcss from 'rollup-plugin-postcss'
import simplevars from 'postcss-simple-vars';
import nested from 'postcss-nested';
import postcssPresetEnv from 'postcss-preset-env';
import cssnano from 'cssnano';
import serve from 'rollup-plugin-serve'
import { eslint } from 'rollup-plugin-eslint'

export default {
    input: "src/index.ts",
    output: {
        name: "test",
        format: "umd",
        file: path.resolve("dist/bundle.js"),  //输出文件路径
        sourcemap: true //生成映射文件
    },
    plugins: [
        resolve({
            extensions: [".js", ".ts", ".tsx"],
        }),
        postcss({
            plugins: [
                // require("autoprefixer")({ overrideBrowserslist: ["> 0.15% in CN"] })
                simplevars(),
                nested(),
                // cssnext({ warnForDuplicates: false, }),
                postcssPresetEnv(),
                cssnano(),
            ],
            extensions: ['.css', ".less", ".scss"]
        }),
        ts({
            tsconfig: path.resolve(__dirname, "tsconfig.json")
        }),
        replace({
            "process.env.NODE_ENV": JSON.stringify("development")
        }),
        // eslint({
        //     include: ['src/**/*.tsx'],
        //     exclude: ['node_modules/**']
        // }),
        babel({
            babelrc: false,
            comments: false,
            sourceMap: false,
            presets: [
                ['@babel/preset-env']
            ],
            plugins: [
                "@babel/plugin-external-helpers"
            ],
            exclude: 'node_modules/**',
            runtimeHelpers: true
        }),
        commonjs(),
        json({
            include: "node_modules/**",
            compact: true,
            namedExports: true,
        }),
    ]
}